<?php
/**
 * Created by PhpStorm.
 * User: ZT
 * Date: 2020/6/18 0018
 * Time: 13:17
 **/

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/13 0013
 * Time: 下午 9:46
 */

namespace frontend\controllers;
use common\component\Constant;
use common\models\info\Tags;
use common\models\info\TagsRelation;
use common\utils\CommonUtil;
use frontend\component\FrontendBaseController;
use Yii;
use yii\web\Controller;

class TagController extends FrontendBaseController
{
    public $layout = "/main";

    public function actionIndex(){
        $data =TagsRelation::getAllTags();
        return $this->render('index',[
            'data' => $data
        ]);
    }
    public function actionDetail(){
        $get = \Yii::$app->request->get();
        $tag_id = $get['aid'];
        $page =isset($get['page'])?$get['page']:1;
        $rows = Tags::getFieldById($tag_id);
        $data =TagsRelation::getArticleByTagId($tag_id,$page,15);
        return $this->render('detail',[
            'data' => $data,
            'name'=>$rows,
            'page'=>$page,
            'pageSize'=>10,
            'url'=>'/tag/'.$tag_id.'.html?page=',
            'breadcrumbs' => [
                [
                    'label'=> '标签',
                    'url'=>'/tags.html'
                ],
                [
                    'label'=> $rows,
                    'url'=>CommonUtil::generateUrl($tag_id,Constant::ROUTE_TAG)
                ],
            ]
        ]);

    }

}